define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'learn/livecoursedown/index' + location.search,
                    multi_url: 'learn/livecoursedown/multi',
                    table: 'learn_livecoursedown',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'id', title: __('序号')},
                        {field: 'name', title: __('Name'), operate:'LIKE'},
                        {field: 'series.name', title: __('系列名称'), operate:'LIKE'},
                        {field: 'start_time', title: __('课程开始时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: __('课程结束时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 't_name', title: __('主讲老师'), operate:'LIKE'},
                        {field: 'introduce', title: __('老师简介'), operate:false},
                        {field: 'origin_price', title: __('Origin_price'), operate:'BETWEEN'},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'visitor_origin_price', title: __('Visitor_origin_price'), operate:false},
                        {field: 'visitor_price', title: __('Visitor_price'), operate:false},
                        //{field: 'buy_numbers', title: __('Buy_numbers')},
                        //{field: 'image', title: __('Image'), operate:false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        //{field: 'thumbs', title: __('Thumbs'), operate:'>='},
                        //{field: 'status', title: __('Status'), operate:false, searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        //{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'download',
                                    title: __('立即下载'),
                                    classname: 'btn btn-xs btn-primary btn-click',
                                    icon: 'fa fa-download',
                                    click: function (data,info) {
                                        if(info.file == ''){
                                            Layer.alert("暂无视频/音频文件！");
                                        }else{
                                            window.open(info.file);
                                        }
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
                searchFormVisible: false,
                commonSearch: false,
                search:true,
                onLoadSuccess:function(){
                    // 这里就是数据渲染结束后的回调函数
                    $(".btn-editone").data("area", ["100%","100%"]);
                }
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));

            }
        }

    };
    return Controller;
});